<tagLib name="html" />

<include file="Public:header" />

<script type="text/javascript">

function isUndefined(variable) {
	return typeof variable == 'undefined' ? true : false;
}

function insertUnit(text, textend) {
	Q('permission').focus();
	textend = isUndefined(textend) ? '' : textend;
	if(!isUndefined(Q('permission').selectionStart)) {
		var opn = Q('permission').selectionStart + 0;
		if(textend != '') {
			text = text + Q('permission').value.substring(Q('permission').selectionStart, Q('permission').selectionEnd) + textend;
		}
		Q('permission').value = Q('permission').value.substr(0, Q('permission').selectionStart) + text + Q('permission').value.substr(Q('permission').selectionEnd);
	} else if(document.selection && document.selection.createRange) {
		var sel = document.selection.createRange();
		if(textend != '') {
			text = text + sel.text + textend;
		}
		sel.text = text.replace(/\r?\n/g, '\r\n');
		sel.moveStart('character', -strlen(text));
	} else {
		Q('permission').value += text;
	}
	formulaexp();
}

var find = new Array('point_count', 'question_count', 'answer_count', 'comment_count', 'best_answer_count', 'follower_count', 'register_date', 'and', 'or', '>=', '<=');
var replace = new Array('<u>{$Think.lang.medal.exp_point_count}</u>', '<u>{$Think.lang.medal.exp_question_count}</u>', '<u>{$Think.lang.medal.exp_answer_count}</u>', '<u>{$Think.lang.medal.exp_comment_count}</u>', '<u>{$Think.lang.medal.exp_best_answer_count}</u>', '<u>{$Think.lang.medal.exp_follower_count}</u>', '<u>{$Think.lang.medal.exp_register_date}</u>', '&nbsp;&nbsp;and&nbsp;&nbsp;', '&nbsp;&nbsp;or&nbsp;&nbsp;', '&ge;', '&le;');
function formulaexp() {
	var result = Q('permission').value;
	for (var i=0; i<replace.length; i++) {
        result = result.replace(find[i], replace[i]);
    }
    Q('formulapermexp').innerHTML = result;
}
</script>

<div class="container" id="cpcontainer">
    <div class="itemtitle">
        <h3>{$Think.lang.medal.manage_medal}</h3>
        <ul class="tab1">
            <li><a href="__URL__/medalList"><span>{$Think.lang.medal.all_medal}</span></a></li>
            <li><a href="__URL__/approveMedal"><span>{$Think.lang.medal.approve_medal}</span></a></li>
        </ul>
    </div>
    <form name="cpform" method="post" action="__ACTION__">
    <input type="hidden" name="op" value="save" />
    <input type="hidden" name="medal_id" value="{$rs.medal_id}" />
    <table class="tb tb2">
        <th class="partition" colspan="2">{$Think.lang.medal.manage_medal} :: {$Think.lang.medal.edit_medal}</th>
        <tr class="nobg"><td colspan="2" class="td27">{$Think.lang.name}:</td></tr>
        <tr>
            <td class="vtop rowform"><input name="name" value="{$rs.name}" type="text" class="txt" /></td>
            <td class="vtop tips2"></td>
        </tr>
        <tr class="nobg"><td colspan="2" class="td27">{$Think.lang.medal.medal_image}:</td></tr>
        <tr>
            <td class="vtop rowform"><input name="image" value="{$rs.image}" type="text" class="txt" /><img src="__PUBLIC__/Images/Medals/{$rs.image}"></td>
            <td class="vtop tips2"></td>
        </tr>
        <tr class="nobg"><td colspan="2" class="td27">{$Think.lang.medal.medal_expiration}:</td></tr>
        <tr>
            <td class="vtop rowform"><input name="expiration" value="{$rs.expiration}" type="text" class="txt" /></td>
            <td class="vtop tips2">{$Think.lang.medal.medal_expiration_explain}</td>
        </tr>
        <tr class="nobg"><td colspan="2" class="td27">{$Think.lang.description}:</td></tr>
        <tr>
            <td class="vtop rowform"><input name="description" value="{$rs.description}" type="text" class="txt" /></td>
            <td class="vtop tips2"></td>
        </tr>
        <tr class="nobg"><td colspan="2" class="td27">{$Think.lang.medal.award_type}:</td></tr>
        <tr>
            <td class="vtop rowform">
                <html:radio name="award_type" radios="medalAwardTypeRadios" checked="medalAwardTypeChecked" separator=" " />
            </td>
            <td class="vtop tips2"></td>
        </tr>
        <tr><th class="partition" colspan="15">{$Think.lang.medal.medal_expression}</th></tr>
        <tr>
            <td colspan="2">
            <div class="extcredits">
            <a href="###" onclick="insertUnit('point_count')">{$Think.lang.medal.exp_point_count}</a> &nbsp;
            <a href="###" onclick="insertUnit('question_count')">{$Think.lang.medal.exp_question_count}</a> &nbsp;
            <a href="###" onclick="insertUnit('answer_count')">{$Think.lang.medal.exp_answer_count}</a> &nbsp;
            <a href="###" onclick="insertUnit('comment_count')">{$Think.lang.medal.exp_comment_count}</a> &nbsp;
            <a href="###" onclick="insertUnit('best_answer_count')">{$Think.lang.medal.exp_best_answer_count}</a> &nbsp;
            <a href="###" onclick="insertUnit('follower_count')">{$Think.lang.medal.exp_follower_count}</a> &nbsp;
            <a href="###" onclick="insertUnit('register_date')">{$Think.lang.medal.exp_register_date}</a> &nbsp;<br />
            <a href="###" onclick="insertUnit(' + ')">&nbsp;+&nbsp;</a>&nbsp;
            <a href="###" onclick="insertUnit(' - ')">&nbsp;-&nbsp;</a>&nbsp;
            <a href="###" onclick="insertUnit(' * ')">&nbsp;*&nbsp;</a>&nbsp;
            <a href="###" onclick="insertUnit(' / ')">&nbsp;/&nbsp;</a>&nbsp;
            <a href="###" onclick="insertUnit(' > ')">&nbsp;>&nbsp;</a>&nbsp;
            <a href="###" onclick="insertUnit(' >= ')">&nbsp;>=&nbsp;</a>&nbsp;
            <a href="###" onclick="insertUnit(' < ')">&nbsp;<&nbsp;</a>&nbsp;
            <a href="###" onclick="insertUnit(' <= ')">&nbsp;<=&nbsp;</a>&nbsp;
            <a href="###" onclick="insertUnit(' = ')">&nbsp;=&nbsp;</a>&nbsp;
            <a href="###" onclick="insertUnit(' (', ') ')">&nbsp;(&nbsp;)&nbsp;</a>&nbsp;
            <a href="###" onclick="insertUnit(' and ')">&nbsp;And&nbsp;</a>&nbsp;
            <a href="###" onclick="insertUnit(' or ')">&nbsp;Or&nbsp;</a>&nbsp;<br />
            </div>
            <div id="formulapermexp" class="marginbot diffcolor2"></div>
            <textarea name="permission" id="permission" style="width: 50%" rows="3" onkeyup="formulaexp();">{$rs.permission}</textarea>
            <br /><br /><span class="smalltxt">{$Think.lang.medal.exp_explain}</span>
            <script type="text/javascript">formulaexp();</script>
            </td>
        </tr>
        <tr class="nobg"><td colspan="15"><div class="fixsel"><input class="btn" type="submit" value="{$Think.lang.submit}" /></div></td></tr>
    </table>
    </form>
</div>

<include file="Public:footer" />
